<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:gl="http://www.gltrade.com/xml" version="1.0">

    <xsl:template name="nongraphical.admonition.as.blocks">
        <xsl:param name="label.contents" />
        <xsl:element name="fo:block" use-attribute-sets="nongraphical.admonition.as.blocks.properties">
            <xsl:if test="$admon.textlabel != 0 or title">
                <!-- make admon title -->
                <xsl:element name="fo:block" use-attribute-sets="admonition.title.properties">
                    <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="$admonition.as.coloured-block">
                            <xsl:element name="fo:block"
                                use-attribute-sets="admonition.as.coloured-block.title.properties">
                                <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
                                <xsl:call-template name="put.into.padded.block">
                                    <xsl:with-param name="contents">
                                        <xsl:value-of select="$label.contents" />
                                    </xsl:with-param>
                                </xsl:call-template>
                            </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="put.into.padded.block">
                                <xsl:with-param name="contents">
                                    <xsl:value-of select="$label.contents" />
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:element>
            </xsl:if>
            <!-- make admon body -->
            <xsl:element name="fo:block" use-attribute-sets="admonition.properties">
                <xsl:choose>
                    <xsl:when test="$admonition.as.coloured-block">
                        <xsl:element name="fo:block"
                            use-attribute-sets="admonition.as.coloured-block.properties">
                            <xsl:call-template name="put.into.padded.block">
                                <xsl:with-param name="contents">
                                    <xsl:apply-templates />
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="put.into.padded.block">
                            <xsl:with-param name="contents">
                                <xsl:apply-templates />
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template name="nongraphical.admonition.as.list-item">
        <xsl:param name="label.length" />
        <xsl:param name="label.contents" />
        <xsl:element name="fo:list-block">
            <xsl:attribute name="provisional-distance-between-starts">
                <xsl:value-of select="$label.length" />
            </xsl:attribute>
            <xsl:attribute name="provisional-label-separation">0.2em</xsl:attribute>
            <xsl:element name="fo:list-item">
                <xsl:element name="fo:list-item-label">
                    <xsl:attribute name="end-indent">label-end()</xsl:attribute>
                    <xsl:attribute name="text-align">start</xsl:attribute>
                    <xsl:if test="$admon.textlabel != 0 or title">
                        <xsl:element name="fo:block"
                            use-attribute-sets="admonition.title.properties">
                            <xsl:value-of select="$label.contents" />
                        </xsl:element>
                    </xsl:if>
                </xsl:element>
                <xsl:element name="fo:list-item-body">
                    <xsl:attribute name="start-indent">body-start()</xsl:attribute>
                    <xsl:element name="fo:block" use-attribute-sets="admonition.properties">
                        <xsl:attribute name="border-left-style">solid</xsl:attribute>
                        <xsl:attribute name="border-left-color">
                            <xsl:value-of select="$title.font.color" />
                        </xsl:attribute>
                        <xsl:attribute name="border-left-width">thin</xsl:attribute>
                        <xsl:attribute name="padding-start">0.5em</xsl:attribute>
                        <xsl:apply-templates />
                    </xsl:element>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template name="put.into.padded.block">
        <!-- FBA : this is a workaround for shitty padding in FO. Using margins. -->
        <xsl:param name="contents" />
        <xsl:param name="padding-h">3pt</xsl:param>
        <xsl:param name="padding-v" select="concat($padding-h,' div 3')" />
        <xsl:element name="fo:block">
            <xsl:attribute name="margin-left">
                <xsl:value-of select="$padding-h" />
            </xsl:attribute>
            <xsl:attribute name="margin-top">
                <xsl:value-of select="$padding-v" />
            </xsl:attribute>
            <xsl:attribute name="margin-bottom">
                <xsl:value-of select="$padding-v" />
            </xsl:attribute>
            <xsl:attribute name="margin-right">
                <xsl:value-of select="$padding-h" />
            </xsl:attribute>
            <xsl:copy-of select="$contents" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>
